package com.servlet;

import com.service.UserService;
import com.service.UserServiceImp;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/checkUsername")
public class CheckUsernameServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String username = request.getParameter("username");
        //调用业务测
        UserService userService = new UserServiceImp();
        //判断用户是否存在
        boolean isExist =  userService.isExist(username);
        //向客户端发送结果信息
        response.getWriter().write("{\"isExist\":"+isExist+"}");

        System.out.println("username="+username);
    }
}
